<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="get">get</button>
    <button class="post">post</button>
</body>
<script>
    var getBtn = document.getElementsByClassName("get")[0];
    var postBtn = document.getElementsByClassName("post")[0];

    getBtn.onclick = function () {

        var user = "a123123";

        var xhr = new XMLHttpRequest();

        xhr.open("get", `../php/isExistUser.php?user=${user}`, true);

        xhr.send();

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                var result = xhr.responseText;
                console.log(result);
                result = JSON.parse(result);
                console.log(result);

                /* var { status, msg } = result;

                if (status) {
                    userSpan.textContent = "√";
                    userSpan.className = "right";
                    isUserOk = true;
                } else {
                    userSpan.textContent = "用户名已存在";
                    userSpan.className = "err";
                } */

            }
        }
    }

    postBtn.onclick = function () {
        var user = "a123123";
        var pwd = 123123;

        var xhr = new XMLHttpRequest();

        xhr.open("post", "../php/login.php", true);

        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(`user=${user}&pwd=${pwd}`);

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                var result = xhr.responseText;
                console.log(result);
                result = JSON.parse(result);
                console.log(result);

                var { status, msg } = result;

                /* if (status) {
                    if (isRem.checked) {
                        setCookie("lgc", user, 7);
                    } else {
                        setCookie("lgc", user);
                    }
                    location.href = "index1.html";
                } else {
                    // alert(msg);
                    pwdSpan.textContent = msg;
                    pwdSpan.className = "err";
                } */

            }
        }
    }


</script>

</html>